import {Body, Controller, Post, UseGuards} from "@nestjs/common";
import {WebUserService} from "./web-user.service";
import {ResultData} from "../../../common/utils/result";
import {JwtWebAuthGuard} from "../../../common/guards/jwt-web-auth.guard";
import {resetPwdDto, SendValidCodeDto, validCodeDto} from "./dto/req-web-user.dto";
import {CacheEnum} from "../../../common/enum";


@Controller('web/user')
export class WebUserController {
    constructor(
        private readonly webUserService: WebUserService
    ) {}


    /**
     * 获取验证码
     * @param body
     */
    @Post('/sendValidCode')
    async sendValidCode(@Body() body:SendValidCodeDto ){
        if(body.type === '1'){
            return ResultData.fail(400, '手机号方式暂不支持')
        }
        // 邮箱验证
        return  await this.webUserService.sendEmailVerificationCode(body.account)
    }


    /**
     * 账号(邮箱、手机)和验证码获取token
     * 验证通过后返回一个用于后续操作的密钥
     */
    @Post('/verifyValidCode')
    async verifyCode(@Body() body: validCodeDto) {
        if(body.type === '1'){
            return ResultData.fail(400, '手机号方式暂不支持')
        }
        return await this.webUserService.verifyCodeAndGenerateKey(body.account, body.code,'email')
    }

    /**
     * 重置密码
     * @param body
     */
    @Post('/findResetPwd')
    async findResetPwd(@Body() body: resetPwdDto) {
        return await this.webUserService.resetPassword(body)
    }



}
